<!DOCTYPE html>
<html>
<head>
  <title>题库模板</title>
  <link href="/qcby/layuiadmin/layui/css/layui.css" rel="stylesheet" type="text/css">
  <link href="/qcby/layuiadmin/global.css" rel="stylesheet" type="text/css">
</head>
<body style="padding:10px;">
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<!--表格数据开始-->
<table id="test" lay-filter="test" ></table>
<script type="text/html" id="paiming"></script>
<div id="myToolBar" style="display: none">
  <button class='layui-btn' lay-event="add" id="addti">导出试题生成预览试卷</button>
</div>

<script src="/qcby/layuiadmin/layui/layui.js"></script>
<script src="/qcby/layuiadmin/modules/cookie.js"></script>
<script>
  layui.use(["element", "jquery", "layer", "form","table"], function () {
    var element = layui.element;
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;

    let cookie = layui.cookie;
    let session = $.cookie('the_cookie');
    if(session == null || session == ""){
      layer.alert("您还未登录，请先登录",{icon:5},function () {
        location.href="/qcby/views/user/login.html";
      });
    }


    let url = decodeURI(window.location.href);
    let argsIndex = url.split("=");
    let arg = argsIndex[1];

    let pro = arg.split("&");
    //获取学科类别
    let project = pro[0];
    //获取班级
    let cla_name = argsIndex[2];
    // console.info(project + cla_name);
    let  myurl = "/qcby/teacher/impor?testObj=" + project;
    //初始化表格
    var myTable = table.render({
      elem: '#test'
      ,title:"我的表格"
      ,height: "full"
      ,url: myurl //数据接口
      ,toolbar:"#myToolBar"
      ,defaultToolbar:[]
      ,page:true
      //,limit:5
      //,limits:[30,60,90]
      ,loading:true
      ,totalRow: true
      ,initSort: {
        field: 'id' //排序字段，对应 cols 设定的各字段名
        ,type: 'asc' //排序方式  asc: 升序、desc: 降序、null: 默认排序
      }
      ,text:{
        none: '暂无数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
      }
      ,cols: [
        [ //表头
          {type: 'checkbox', fixed: 'left'}
          // ,{field: 'id', title: 'ID', width:80}
          ,{field: 'paiming', title: '序号', width:80,templet:'#zizeng',type: 'numbers',}
          ,{field: 'project', title: '学科',edit:"text",align:"center" }
          ,{field: 'topic', title: '题目',edit:"text",align:"center" }
          ,{field: 'type', title: '题型' ,templet: function (data) {
              return data.type == 1 ? "单选" :(data.type == 2 ?"多选" : "简答");
            }}
          ,{field: 'a', title: '选项A',}
          ,{field: 'b', title: '选项B',}
          ,{field: 'c', title: '选项C', }
          ,{field: 'd', title: '选项D', }
          ,{field: 'answer', title: '答案',edit:"text"}
          ,{field: 'parsing', title: '解析', edit:"text"}
          ,{field: 'difficult', title: '难易程度',}
          ,{field: 'fraction', title: '分数',}
          ,{field: 'rig', title: '正确率',}
          // ,{fixed: 'right', title:'操作', toolbar: '#myTool', width:150,align:"center"}
        ]
      ]
    })
    $("#addti").bind("click",function () {
      var checkStatus = table.checkStatus('test'); //idTest 即为基础参数 id 对应的值
      // console.log(checkStatus.data) //获取选中行的数据
      let data = {};

      data["createArr"] = checkStatus.data;
      $.ajax({
        type: 'post',
        url: '/qcby/teacher/impTiku',
        data: JSON.stringify(data),
        contentType: "application/json;charsetset=UTF-8",//必须
        dataType: "json",
        cache: false,
        async: false,
        success: function (rep) {

          if (rep.code == 0) {
            let testId = rep.data;
            let tourl = "/qcby/teacher/yulan?testTitle="+project+"&testId="+testId+"&project="+project+"&cla_name="+cla_name+"&difficult=未知";
            layer.msg('导入成功', {
              offset: '15px'
              , icon: 1
              , time: 1000
            }, function () {
              window.location.href = tourl;
            });
          } else {
            layer.msg(rep.msg, {
              offset: '30px'
              , icon: 2
              , time: 1000
            }, function () {
              location.reload();
            });
          }

        }

        // console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
        // console.log(checkStatus.isAll ) //表格是否全选
      });
    });

  })
</script>
</body>
</html>
